package com.boco.wmworkflow.common.xmlmodel;

import java.util.*;
import com.boco.webmaster.common.xsdmap.workflow.wfcfg.*;

public class WfSheetXmlModelFactory {
    private static WfSheetXmlModelFactory instance;
    private Map wfSheetModelTable = new HashMap();

    public static WfSheetXmlModelFactory createInstance(WfCfgType[] wfCfgs) throws Exception{
        if(instance == null){
            instance = new WfSheetXmlModelFactory(wfCfgs);
        }
        return instance;
    }

    public static WfSheetXmlModelFactory getInstance(){
        return instance;
    }

    private WfSheetXmlModelFactory(WfCfgType[] wfCfgs)  throws Exception{
        for(int i=0; i<wfCfgs.length; i++){
            List sheetCfgList = wfCfgs[i].getSheetList();
            for(int j=0; j<sheetCfgList.size(); j++){
                NameValueType nv = (NameValueType) sheetCfgList.get(j);
                String filePath = nv.getValue();
                WfSheetXmlModel sheetModel = new WfSheetXmlModel("xmlmodel/" + filePath);
                wfSheetModelTable.put(nv.getName(), sheetModel);
            }
        }
    }

    public WfSheetXmlModel getSheetModel(String sheetName){
        return (WfSheetXmlModel) wfSheetModelTable.get(sheetName);
    }
}
